$(function(){
    $.validator.setDefaults({
        submitHandler: function(form){
            form.submit();
        }
    });
	$.validator.addMethod("alnum", function(value, element) {
      return this.optional(element) || /^[a-zA-Z0-9]+$/.test(value);
     }, "只能包括英文字母和数字");
	$.validator.addMethod("dateTimeFormat", function(value,element){  
	    return this.optional(element) || /^\d{4}-(?:0\d|1[0-2])-(?:[0-2]\d|3[01])( (?:[01]\d|2[0-3])\:[0-5]\d\:[0-5]\d)?$/.test(value);  
	}, "输入正确的时间");
    $("#form").validate({
        errorPlacement: function(error, element){
            error.appendTo(element.parent());
        },
        rules: {
            "opentime": {
                required: true,
                dateTimeFormat: true
            },
            "name": {
                required: true
            },
            "qq":{
            	digits:true
            },
            "index":{
              url: true,
              required: true
            },
            "top": {
                required: true,
                minlength: 1,
                maxlength: 1,
                digits:true
            },
            "type": {
            	 required: true,
                 minlength: 1,
                 maxlength: 2,
                 digits:true
            },
            "weight": {
           	    required: true,
                minlength: 1,
                maxlength: 2,
                digits:true
           },
           "enable":{
        	   required: true,
               minlength: 1,
               maxlength: 1,
               digits:true
           },
           "seq":{
        	   required: true,
               minlength: 1,
               maxlength: 11,
               digits:true
           }
        },
        messages: {
        	 "opentime": {
                 required: "opentime 不可为空"
             },
             "name": {
                 required:"name 不可为空"
             },
             "qq":{
             	digits:"qq 必须是数字"
             },
             "index":{
               url: "index 必须符合http://",
               required: "index 不得为空"
             },
             "top": {
                 required: "不可为空",
                 minlength: "长度为1",
                 maxlength: "长度为1",
                 digits:"必须是数字"
             },
             "type": {
             	 required: "不可为空",
                  minlength: "长度不得小于1",
                  maxlength: "长度不得大于2",
                  digits:"必须是数字"
             },
             "weight": {
            	 required: "不可为空",
                 minlength: "长度不得小于1",
                 maxlength: "长度不得大于2",
                 digits:"必须是数字"
            },
            "enable":{
            	 required: "不可为空",
                 minlength: "长度不得小于1",
                 maxlength: "长度不得大于2",
                 digits:"必须是数字"
            },
            "seq":{
            	 required: "不可为空",
                 minlength: "长度不得小于1",
                 maxlength: "长度不得大于11",
                 digits:"必须是数字"
            }
        }
    });
    $("input[name$='time']").datetimepicker({
        changeMonth: true,
        changeYear: true,
        dateFormat: 'yy-mm-dd',
        timeFormat: 'HH:mm:ss'
    });
});
